// @/utils/message.ts
import { ElMessage } from 'element-plus'
import { showSuccessToast, showFailToast, showToast } from 'vant'
import { isPC } from '@/utils/device'

// 定义消息类型
type MessageType = 'success' | 'error' | 'warning' | 'info' | 'primary'

// 统一的消息提示函数
export const showToastMessage = (typestr: MessageType, messagetext: string) => {
  if (isPC()) {
    ElMessage({
      message: messagetext,
      type: typestr,
    })
  } else {
    // Vant Toast 映射
    const toastMap: Record<MessageType, () => void> = {
      success: () => showSuccessToast(messagetext),
      error: () => showFailToast(messagetext),
      primary: () => showToast(messagetext),
      warning: () => showFailToast(messagetext),
      info: () => showToast(messagetext),
    }

    const toastFn = toastMap[typestr] || toastMap.info
    toastFn()
  }
}
